package prac5;
/**
 * Implements the fighter.
 * 
 * @author			Ian Moriarty
 * @author			Menghong Li
 * @modified		Menghong Li (Aug 2011)- - JavaDoc / Indentation / Style 
 *					Menghong Li & Ian Moriarty - Expanded to meet the requirements of Prac 5
 * @since			21th August 2011
 * @input			none
 * @output			only for regression testing
 * @errorHandling	none
 * @knownBugs		none
 */

public abstract class Fighter {
	/** represents the life points of the fighter  */
	private int life;
	/** represents the experience points of the fighter  */
	private int experience;
	
	/**
	 * Implements each fighter.
	 *
	 * @author	    Ian Moriarty
	 * @modified    Menghong Li (Aug 2011) - JavaDoc / Indentation / Style
	 * @param		Initial life points and initial experience points
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public Fighter(int initLife, int initExperience) {
		if (initLife >= 0 && initExperience >= 0) {
			life = initLife;
			experience = initExperience;
		} else {
			System.out.println("Error: Cannot create a fighter with negative life or experience.");
		}
	}
	
	/**
	 * @return		the life of the fighter
	 * @complexity	Best and Worst case: O(1)
	 */
	public int getLife() {
		return life;
	}

	/**
	 * @param		life the life to set
	 * @pre			The life cannot be less than 0
	 * @complexity	Best and worst case: O(1)
	 */
	public void setLife(int life) {
		if(life >= 0){
			this.life = life;
		}else {
			System.out.println("Error: Cannot set a fighter with negative(< 0) life.");
		}
	}

	/**
	 * @param		experience the experience to set
	 * @pre			experience must be non-negative
	 * @complexity	Best and Worst case: O(1)
	 */
	public void setExperience(int experience) {
		if (experience >= 0) {
			this.experience = experience;
		} else {
			System.out.println("Error: Cannot have negative experience");
		}
	}
	
	/**
	 * To check whether fighter is still alive.
	 *
	 * @return		Returns true if the fighter's life is greater than 0, false otherwise.
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public boolean isAlive() {
		return (this.life > 0);
	}
	
	/**
	 * Decreases the life of the unit by the amount indicated by lostLife.
	 *
	 * @param		lostLife - Lost life after defence
	 * @pre         lostLife must be positive
	 * @post        Life of the unit decreased by the amount indicated by lostLife.
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public void loseLife(int lostLife) {
		if (lostLife >= 0) {
			life -= lostLife;
		} else {
			System.out.println("Error: Cannot lose a negative amount of life.");
		}
	}
	
	/**
	 * Increases the experience of the unit by the amount indicated by gainedExperience.
	 *
	 * @param		gainedExperience - The experience that the unit gain after combat.
	 * @pre         gainedExperience must be positive
	 * @post        Experience of the unit increased by the amount indicated by gainedExperience.
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public void gainExperience(int gainedExperience) {
		if (gainedExperience >= 0) {
			experience += gainedExperience;
		} else {
			System.out.println("Error: Cannot gain a negative amount of experience.");
		}
	}
	
	/**
	 * Returns the experience of the unit
	 *
	 * @return      Returns the experience of the unit. 
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public int getExperience() {
		return experience;
	}
	
	/**
	 * Returns the speed of the unit
	 *
	 * @return      Returns the speed of the unit. 
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public abstract int getSpeed();
	
	/**
	 * Returns the amount of damage performed by the unit when it attacks.
	 *
	 * @return      returns the amount of damage performed by the unit when it attacks. 
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public abstract int attackDamage();
	
	/**
	 * decreases the life of the unit by the amount lost (if any) after defending from an attack that indicated the amount of damage indicated by damage.
	 *
	 * @param       the amount of damage performed by the unit when it attacks.
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public abstract void defend(int attackDamage);
	
	
	
	/**
	 * Returns a string indicating the type of unit, its current life and experience.
	 *
	 * @return      Returns a string indicating the type of unit, its current life and experience.
	 * @complexity	best and worst case: O(1)
	 *			
	 */
	public abstract String toString();
}
